import React, { Component } from 'react'
import PropTypes from 'prop-types'
import InputOpenWin from '../InputOpenWin'
import {HTTP, getOrganNo} from "../../../utils";
import { productSpecsList } from '../../../utils/api'


export default class extends Component {

    constructor(props) {
        super(props)
        this.input = undefined
        this.state = {
            tableSeaExtendVal: {}
        }
    }

    componentDidMount() {
        if(this.props.initVal ===  undefined || this.props.initVal === null || this.props.initVal == "") {

        } else {
            HTTP.post(productSpecsList, {id: this.props.initVal}, () => {
            }, (resp) => {
                const name = ((((resp || {})['data'] || [])[0] || {}))['name']
                this.input.setText(name)
            })
        }
    }

    tableSeaField = [{
        label: '产品规格名称',
        key: 'specsName'
    }]

    tableUrl = productSpecsList

    tableColumn = [{
        title: '规格名称',
        dataIndex: 'specsName',
        key: 'specsName',
    }, {
        title: '规格代码',
        dataIndex: 'specsCode',
        key: 'specsCode',
    }]



    render = () => {
        return (
            <InputOpenWin
                ref={(e) => {this.input=e}}
                tableTitle="规格列表"
                tableSeaField={this.tableSeaField}
                tableSeaExtendVal={this.state.tableSeaExtendVal}
                tableUrl={this.tableUrl}
                tableColumn={this.tableColumn}
                valueField="specsName"
                keyField="specsCode"
                {...this.props}
            />
        )
    }

    empty = () => {
        this.input.empty()
    }

    setTableSeaExtendVal = (v) => {
        this.setState({
            tableSeaExtendVal: v
        })
    }
}
